package com.example.mapper;

import com.example.entity.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @auth shanyue
 * @date 2025年06月06日15:10
 */
@Mapper
public interface BookMapper {
    @Select("SELECT * FROM books")
    List<Book> findAll();

    @Select("SELECT * FROM books WHERE id = #{id}")
    Book findById(Integer id);

    @Insert("INSERT INTO books(title, author, isbn, stock) VALUES(#{title}, #{author}, #{isbn}, #{stock})")
    void insert(Book book);

    @Update("UPDATE books SET title=#{title}, author=#{author}, isbn=#{isbn}, stock=#{stock} WHERE id=#{id}")
    void update(Book book);

    @Delete("DELETE FROM books WHERE id=#{id}")
    void delete(Integer id);

    @Update("UPDATE books SET stock = #{stock} WHERE id = #{id}")
    int updateBook(Book book);

    @Update("UPDATE books SET stock = stock + 1 WHERE id = #{bookId}")
    int increaseStock(@Param("bookId") Integer bookId);
}
